<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
</head>
<body style="background-color: white;" class="gray-bg">
	<div class="ibox-content">
		<form class="form-horizontal m-t" id="signupForm" method="post" enctype="multipart/form-data">
			<div class="form-group">
				<label class="col-sm-3 control-label">公司名称：</label>
				<div class="col-sm-8">
				    <input type="hidden" name="id"  value="${company.id }"/>
				    <input type="hidden" class="form-control" id="status" name="status" value="2"/>
					<input type="text" class="form-control" id="name" name="name"  value="${company.name }"/>
					<p class="help-block">名称唯一性，不允许重复添加。</p>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">公司简称：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="shortName" name="shortName"  value="${company.shortName }"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">公司性质：</label>
				<div class="col-sm-8">
				<select class="form-control"  id="nature" name="nature" >
					<option>==请选择==</option>
					<c:forEach items="${fns:getDictList('company_nature')}" var="cnature">
					<option value="${cnature.value }" <c:if test="${company.nature eq cnature.value }">selected</c:if>>${cnature.valueName }</option>
					</c:forEach>
				</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">法定代表人：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="legalPerson" name="legalPerson" value="${company.legalPerson }"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">注册资本：</label>
				<div class="col-sm-8 form-inline">
					<input type="text" class="form-control" id="capital" name="capital" value="${company.capital }"/>(万人民币)
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">公司行业：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="industryName" name="industryNames"  onclick="openTree('industry');" placeholder="请选择行业" readonly="readonly" value="${company.industryNames }"/>
				   <input type="hidden" name="industryId" id="industryId" value="${company.industryId }"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">公司规模：</label>
				<div class="col-sm-8">
				<select class="form-control"  id="scale" name="scale" >
					<option>==请选择==</option>
					<c:forEach items="${fns:getDictList('company_scale')}" var="cscale">
					<option value="${cscale.value }" <c:if test="${company.scale eq cscale.value }">selected</c:if>>${cscale.valueName }</option>
					</c:forEach>
				</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">所在区域：</label>
				<div class="col-sm-8 form-inline">
				    <p class="help-block">${company.area.treeNames }</p> 
				    <select  id="province"  class="form-control"  style="width:30%;"></select>
					<select  id="city" class="form-control"  style="width:30%;display:none;" ></select>
					<select  id="county"  class="form-control" style="width:30%;display:none;" ></select>
					<input type="hidden" id="areaId" name="areaId" value="${company.areaId }"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">总部所在地：</label>
				<div class="col-sm-8">
				    <input type="text" id="headquarter" name="headquarter" class="form-control" value="${company.headquarter }"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">公司投资人或者股东：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="Investor" name="Investor"  value="${company.investor }"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">社会统一信用代码：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="invoice" name="invoice"  value="${company.invoice }" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">公司网址：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="website" name="website" value="${company.website }" onblur="isUrl('website',this.value)"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">公司简介：</label>
				<div class="col-sm-8">
					<textarea rows="3" cols="3" class="form-control" id="profile" name="profile" >${company.profile }</textarea>
					<p class="help-block" style="color: red;">*必填项，如存在企业网站，请填写公司网址</p>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">核心竞争优势：</label>
				<div class="col-sm-8">
					<textarea rows="3" cols="3" class="form-control" id="advantage" name="advantage">${company.advantage }</textarea>
				</div>
			</div>
			<div class="form-group" style="text-align: center;">
				<div class="col-sm-8 col-sm-offset-3">
					<button class="btn btn-primary" type="button" id="sub">提交</button>
				</div>
			</div>
		</form>
	</div>


	<script>
	 $(function () {
	        $("#sub").click(function () {
	        	//调用方式
	        	var arr=new Array(
	        	  new Array('name','公司名称未填写!'),
	        	  new Array('shortName','公司简称未填写!'),
	        	  new Array('industryName','公司行业未选择!'),
	        	  new Array('nature','公司性质未填写!'),
	        	  new Array('headquarter','总部地址未填写!'),
	        	  new Array('scale','公司规模未选择!'),
	        	  new Array('Investor','公司投资人未填写!'),
	        	  new Array('invoice','社会统一信用代码未填写!'),
	        	  new Array('profile','公司简介未填写!')
	        	);
	        	//批量验证表单非空
	        	  for(var i=0;i<arr.length;i++){
		        	  if($("#"+arr[i][0]).val()==''){
		        		  $("#"+arr[i][0]).tips({
		  					side:3,
		  		            msg:arr[i][1],
		  		            bg:'#AE81FF',
		  		            time:1
		  		        });
		        		  $("#"+arr[i][0]).focus();
		  				return;
		  			}
	        	  };
	        	  var areaId="";
	        	  var county = $("#county").val();
	        	  areaId =  $("#areaId").val();
	        	  if(county!=''&& county!=null){
	        		  $("#areaId").val(county);
	        		  areaId = county;
	        	  }
	        	  if(areaId.length==0){
	        		  swal({ 
						  title: "公司区域未选择", 
						  text: "1秒后自动关闭。", 
						  timer: 1000, 
						  showConfirmButton: false 
						});
	        		  return;
	        	  }
	            $("#signupForm").ajaxSubmit({
	                url: '<%=contextPath%>/company/update',
						type : 'post',
						dataType : "json",
						success : function(data) {
							if (data.code == 200) {
								swal({
									title : data.message,
									type : "success",
									showCancelButton : false,
									confirmButtonText : "确定",
									animation : "slide-from-bottom",
									closeOnConfirm : true
								}, function() {
									top.Dialog.close();
								});
							} else {
								swal("错误", data.message, "error");
							}
						}
					});

				});
	    	$.ajax({//查询省
	    		url:"<%=contextPath%>/area/getAreaJson",
	    		data:{pid:0,level:1},
	    		type:"post",
	    		dataType:"json",
	    		success:function(data){
	    			var htm='';
	    			$("#province").append('<option value="">==请选择省直辖市==</option>');
	    			$.each(data,function(i,item){
	    				$("#province").append("<option value='" + item.id + "'>" + item.name + "</option>");
	    			});
	    		}
	    	});	
	    	$("#province").change(function(){//查询市
	    		var pid = $(this).val();
	    		var city = $("#city");
	    		var county = $("#county");
	    		$("#city").show();
	    		$("#county").hide();
	    		if($("#city").children().length > 0) {
	    			city.empty();
	    		}
	    		if($("#county").children().length > 0) {
	    			county.empty();
	    		}
	    		$.ajax({//查询省
	    			url:"<%=contextPath%>/area/getAreaJson",
	    			data:{pid:pid,level:2},
	    			type:"post",
	    			dataType:"json",
	    			success:function(data){
	    				$("#city").append('<option value="">==请选择市州==</option>');
	    				$.each(data,function(i,item){
	    					$("#city").append("<option value='" + item.id + "'>" + item.name + "</option>");
	    				});
	    			}
	    		})
	    	});
	    	$("#city").change(function(){//查询市
	    		var pid = $(this).val();
	    		var county = $("#county");
	    		$("#county").show();
	    		if($("#county").children().length > 0) {
	    			county.empty();
	    		}
	    		$.ajax({//查询省
	    			url:"<%=contextPath%>/area/getAreaJson",
	    			data:{pid:pid,level:3},
	    			type:"post",
	    			dataType:"json",
	    			success:function(data){
	    				$("#county").append('<option value="">==请选择县区==</option>');
	    				$.each(data,function(i,item){
	    					$("#county").append("<option value='" + item.id + "'>" + item.name + "</option>");
	    				});
	    			}
	    		})
	    	});
			});
	  //分配资源
		function openTree(obj){
		  var ids = $("#industryId").val();
			 top.jzts();
		   	 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="请选择";
			 diag.URL = '<%=contextPath %>/'+obj+'/openZtree?ids='+ids;
			 diag.Width = 250;
			 diag.Height = 400;
			 diag.CancelEvent = function(){ //关闭事件
				 var tempid = diag.innerFrame.contentWindow.document.getElementById('tempids').value;
				 var tempname = diag.innerFrame.contentWindow.document.getElementById('tempnames').value;
				if(tempid.length!==0){
					$("#"+obj+"Id").val(tempid);
					$("#"+obj+"Name").val(tempname);
				}
				diag.close();
			 };
			 diag.show();
		}
		</script>
</body>
</html>